package com.ztgf.pay.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.pay.models.bo.PayOrderRepaySaveBO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import com.ztgf.pay.models.service.IPayOrderRepayService;
import com.ztgf.pay.models.bo.PayOrderRepayBO;
import com.ztgf.pay.models.dto.PayOrderRepayDTO;

import java.util.List;

/**
 * 退款订单控制器
 *
 * @author mxli
 * @Date 2020-07-30 12:13:30
 */

@RestController
@RequestMapping("/api/payOrderRepay")
@Slf4j
@Api(value = "PayOrderRepayApiController",tags = "退款订单Api接口")
public class PayOrderRepayApiController {

    @DubboReference
    private IPayOrderRepayService payOrderRepayService;

    @PostMapping("/saveBalanceOrderRepay")
    @ApiOperation(value = "余额退款",notes = "余额退款")
    public Result<PayOrderRepayDTO> saveBalanceOrderRepay(PayOrderRepaySaveBO saveBO){
        return payOrderRepayService.saveBalanceOrderRepay(saveBO);
    }

    @PostMapping("/saveOnlineBankOrderRepay")
    @ApiOperation(value = "网银退款",notes = "网银退款")
    public Result<PayOrderRepayDTO> saveOnlineBankOrderRepay(PayOrderRepaySaveBO saveBO){
        return payOrderRepayService.saveOnlineBankOrderRepay(saveBO);
    }

    @PostMapping("/saveOnlineBankRepayLog")
    @ApiOperation(value = "保存查询网银退款状态",notes = "保存查询网银退款状态")
    public void saveOnlineBankRepayLog(){
        Wrapper wrapper = new EntityWrapper();
        wrapper.eq("type", 1);
        Object[] status = {0, 1};
        wrapper.in("status", status);
        List<PayOrderRepayDTO> list = payOrderRepayService.selectList(wrapper);
        if(list != null && list.size() > 0){
            for (PayOrderRepayDTO dto : list) {
                payOrderRepayService.saveOnlineBankRepayLog(dto);
            }
        }
    }

    @PostMapping("/saveBalanceRepayLog")
    @ApiOperation(value = "保存查询余额退款状态",notes = "保存查询余额退款状态")
    public void saveBalanceRepayLog(){
        Wrapper wrapper = new EntityWrapper();
        wrapper.eq("type", 0);
        Object[] status = {0, 1};
        wrapper.in("status", status);
        List<PayOrderRepayDTO> list = payOrderRepayService.selectList(wrapper);
        if(list != null && list.size() > 0){
            for (PayOrderRepayDTO dto : list) {
                payOrderRepayService.saveBalanceRepayLog(dto);
            }
        }
    }

}
